package cn.csc.module.order.dal.mysql.shopcart;

import cn.csc.framework.common.pojo.PageResult;
import cn.csc.framework.mybatis.core.mapper.BaseMapperX;
import cn.csc.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.csc.module.order.controller.app.shopcart.vo.AppShopCartItemExportReqVO;
import cn.csc.module.order.controller.app.shopcart.vo.AppShopCartItemPageReqVO;
import cn.csc.module.order.dal.dataobject.shopcart.ShopCartItemDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.math.BigInteger;
import java.util.List;

/**
 * 购物车 Mapper
 *
 * @author liuchuang
 */
@Mapper
public interface ShopCartItemMapper extends BaseMapperX<ShopCartItemDO> {

    default PageResult<ShopCartItemDO> selectPage(AppShopCartItemPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ShopCartItemDO>()
                .eqIfPresent(ShopCartItemDO::getShopId, reqVO.getShopId())
                .eqIfPresent(ShopCartItemDO::getSpuId, reqVO.getSpuId())
                .eqIfPresent(ShopCartItemDO::getSkuId, reqVO.getSkuId())
                .eqIfPresent(ShopCartItemDO::getUserId, reqVO.getUserId())
                .eqIfPresent(ShopCartItemDO::getCount, reqVO.getCount())
                .eqIfPresent(ShopCartItemDO::getPriceFee, reqVO.getPriceFee())
                .eqIfPresent(ShopCartItemDO::getIsChecked, reqVO.getIsChecked())
                .betweenIfPresent(ShopCartItemDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ShopCartItemDO::getId));
    }

    default List<ShopCartItemDO> selectList(AppShopCartItemExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<ShopCartItemDO>()
                .eqIfPresent(ShopCartItemDO::getShopId, reqVO.getShopId())
                .eqIfPresent(ShopCartItemDO::getSpuId, reqVO.getSpuId())
                .eqIfPresent(ShopCartItemDO::getSkuId, reqVO.getSkuId())
                .eqIfPresent(ShopCartItemDO::getUserId, reqVO.getUserId())
                .eqIfPresent(ShopCartItemDO::getCount, reqVO.getCount())
                .eqIfPresent(ShopCartItemDO::getPriceFee, reqVO.getPriceFee())
                .eqIfPresent(ShopCartItemDO::getIsChecked, reqVO.getIsChecked())
                .betweenIfPresent(ShopCartItemDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ShopCartItemDO::getId));
    }


    default List<ShopCartItemDO> selectShopIdList(BigInteger userId,BigInteger shopId) {
        return selectList(new LambdaQueryWrapperX<ShopCartItemDO>()
                .eqIfPresent(ShopCartItemDO::getUserId, userId)
                .eqIfPresent(ShopCartItemDO::getShopId, shopId)
                .orderByDesc(ShopCartItemDO::getCreateTime));
    }
    default List<ShopCartItemDO> selectShopIdsList(BigInteger userId,List<BigInteger> shopIds) {
        return selectList(new LambdaQueryWrapperX<ShopCartItemDO>()
                .eqIfPresent(ShopCartItemDO::getUserId, userId)
                .eq(ShopCartItemDO::getDeleted, 0)
                .in(ShopCartItemDO::getShopId, shopIds)
                .orderByDesc(ShopCartItemDO::getCreateTime));
    }
    List<ShopCartItemDO> getShopCartItemList(@Param("userId") BigInteger userId);

    List<Long> getShopCartItemIds(@Param("orderId") BigInteger orderId);

    // 物理删除
    Integer deleteShopCartItemByOrderId(List<BigInteger> orderIds);

}
